package com.itqf.service.impl;

import com.itqf.bean.DtsBrand;
import com.itqf.bean.DtsBrandExample;
import com.itqf.mapper.DtsBrandMapper;
import com.itqf.service.DtsBrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * projectName: gp_manage
 *
 * @author: 赵伟风
 * time: 2021/8/18 18:10
 * description:
 */
@Service
public class DtsBrandServiceImpl implements DtsBrandService {

    @Autowired
    private DtsBrandMapper dtsBrandMapper;

    /**
     * 根据管理员id查询对应的品牌id
     *
     * @param id
     * @return
     */
    @Override
    public List<Integer> findBrandIdsByAdminId(Integer id) {

        //1.查询brand集合
        DtsBrandExample example = new DtsBrandExample();

        DtsBrandExample.Criteria criteria = example.createCriteria();

        criteria.andDeletedEqualTo(false);
        criteria.andAdminIdEqualTo(id);

        List<DtsBrand> dtsBrands = dtsBrandMapper.selectByExample(example);

        //2.封装brandId
        List<Integer> brandIds = new ArrayList<>(dtsBrands.size());

        for (DtsBrand dtsBrand : dtsBrands) {
            brandIds.add(dtsBrand.getId());
        }

        return brandIds;
    }
}
